'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
    async up(queryInterface, Sequelize) {
        /**
         * Add altering commands here.
         *
         * Example:
         * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
         */
            // 拼接表前缀
        const pre = 'pre_'; // this.app.config.databaseSchema
        const tableName = pre + 'users';
        // 判断表是否存在
        if (await queryInterface.tableExists(tableName)) {
            return false;
        }

        const {INTEGER, BIGINT, STRING} = Sequelize;
        await queryInterface.createTable(tableName, {
            id: {type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键ID'},
            name: {type: STRING, defaultValue: null, comment: '姓名'},
            age: {type: INTEGER, defaultValue: null, comment: '年龄'},
            created_at: {type: BIGINT.UNSIGNED, defaultValue: null, comment: '创建时间'},
            updated_at: {type: BIGINT.UNSIGNED, defaultValue: null, comment: '更新时间'},
        });
    },

    async down(queryInterface, Sequelize) {
        /**
         * Add reverting commands here.
         *
         * Example:
         * await queryInterface.dropTable('users');
         */
        const pre = 'pre_'; // this.app.config.databaseSchema
        const tableName = pre + 'users';
        await queryInterface.dropTable(tableName);

    }
};
